package com.cw.lang.redis.service.impl;

import java.util.List;
import java.util.Properties;

import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisServerCommands;
import org.springframework.data.redis.core.types.RedisClientInfo;

import com.cw.lang.redis.service.RedisServerService;

import lombok.Getter;
import lombok.Setter;

/**
 * redisTemplate.getRequiredConnectionFactory().getConnection()
 *
 * @author chenw
 * @version $$Id: RedisServerServiceImpl.java, v 0.1 2018/12/25 10:38 AM chenw Exp $$
 */
@Getter
@Setter
public class RedisServerServiceImpl extends AbstractRedisService implements RedisServerService {

    private RedisConnection getConnection() {
        return getRedisTemplate().getRequiredConnectionFactory()
            .getConnection();
    }

    @Override
    public void bgReWriteAof() {
        getConnection().bgReWriteAof();
    }

    @Override
    public void bgSave() {
        getConnection().bgSave();
    }

    @Override
    public Long lastSave() {
        return getConnection().lastSave();
    }

    @Override
    public void save() {
        getConnection().save();
    }

    @Override
    public Long dbSize() {
        return getConnection().dbSize();
    }

    @Override
    public void flushDb() {
        getConnection().flushDb();
    }

    @Override
    public void flushAll() {
        getConnection().flushAll();
    }

    @Override
    public Properties info() {
        return getConnection().info();
    }

    @Override
    public Properties info(String section) {
        return getConnection().info(section);
    }

    @Override
    public void shutdownRedis() {
        getConnection().shutdown();
    }

    @Override
    public void shutdownRedis(RedisServerCommands.ShutdownOption option) {
        getConnection().shutdown(option);
    }

    @Override
    public Properties getConfig(String pattern) {
        return getConnection().getConfig(pattern);
    }

    @Override
    public void setConfig(String param, String value) {
        getConnection().setConfig(param, value);
    }

    @Override
    public void resetConfigStats() {
        getConnection().resetConfigStats();
    }

    @Override
    public Long time() {
        return getConnection().time();
    }

    @Override
    public void killClient(String host, int port) {
        getConnection().killClient(host, port);
    }

    @Override
    public void setClientName(byte[] name) {
        getConnection().setClientName(name);
    }

    @Override
    public String getClientName() {
        return getConnection().getClientName();
    }

    @Override
    public List<RedisClientInfo> getClientList() {
        return getConnection().getClientList();
    }

    @Override
    public void slaveOf(String host, int port) {
        getConnection().slaveOf(host, port);
    }

    @Override
    public void slaveOfNoOne() {
        getConnection().slaveOfNoOne();
    }

    @Override
    public void migrate(byte[] key, RedisNode target, int dbIndex, RedisServerCommands.MigrateOption option) {
        getConnection().migrate(key, target, dbIndex, option);
    }

    @Override
    public void migrate(byte[] key, RedisNode target, int dbIndex, RedisServerCommands.MigrateOption option,
        long timeout) {
        getConnection().migrate(key, target, dbIndex, option, timeout);
    }
}
